package com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.vo.SmsAssetFixedRepairApplyAllowVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.vo.SmsAssetFixedRepairApplyVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.service.SmsAssetFixedRepairApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-06-05
 */
@SecretBody
@RestController
@RequestMapping("/assetFixedRepair")
public class SmsAssetFixedRepairApplyController {
    @Autowired
    SmsAssetFixedRepairApplyService smsAssetFixedRepairApplyService;
    @Autowired
    JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "新增维修申请")
    @PostMapping("/add")
    public ResponseResult addAssetFixedRepair(@RequestBody @Validated SmsAssetFixedRepairApplyVO applyVO,
                                              HttpServletRequest request
                                              ){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.addAssetFixedRepair(applyVO,user_id);
    }
    @ApiModelProperty(value = "撤销维修申请")
    @PostMapping("/cancel")
    public ResponseResult cancelAssetFixedRepair(@RequestBody SmsAssetFixedRepairApplyVO cancelVO,
                                                 HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.cancelAssetFixedRepair(cancelVO,user_id);
    }
    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult assetFixedRepairList(@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "apply_type") Integer apply_type,
                                               HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.assetFixedRepairList(pageSize,pageNum,apply_type,user_id);
    }
    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult assetFixedRepairDetail(@RequestParam(value = "apply_id") String apply_id,
                                                 HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.assetFixedRepairDetail(apply_id,user_id);
    }
    @ApiModelProperty(value = "查询所有申请记录")
    @GetMapping("/selectAll")
    public ResponseResult selectAllAssetFixedRepairApply(
            @RequestParam(value = "apply_person",required = false) String apply_person,
            @RequestParam(value = "apply_department",required = false) String apply_department,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum
    ){
        return smsAssetFixedRepairApplyService.selectAllAssetFixedRepairApply(apply_person,
                apply_department,pageSize,pageNum);
    }
    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowRepairApply(@RequestBody SmsAssetFixedRepairApplyAllowVO allowVO,
                                           HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.allowRepairApply(allowVO,user_id);
    }
    @ApiModelProperty("查询我的资产")
    @GetMapping("/selectMyAssetByUserId")
    public ResponseResult selectMyAsset(@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                        @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                        HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedRepairApplyService.selectMyAsset(pageSize,pageNum,user_id);
    }
}

